<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>南京大学职业咨询室预约平台</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='assets/i/ico_128X128.ico') }}">
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="apple-touch-icon-precomposed" href="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <meta name="msapplication-TileColor" content="#0e90d2">

    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/amazeui.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/app.css', v='1.4') }}">
    <script src="{{ url_for('static', filename='assets/js/jquery.min.js') }}"></script>
    <script src="{{ url_for('static', filename='assets/js/amazeui.min.js') }}"></script>
</head>

<body>
<div class="admin-header">
    <!--<div class="header-back" onclick="history.back()">返回</div>-->
    <div class="header-title">咨询室故事列表</div>
</div>
<div class="content">
    {% for li in lists %}
    <div class="book-item-warp">
        <div class="book-item-title">
            <div class="fl" style="line-height:20px;"> <strong>{{loop.index}}、</strong>{{li['title']}}</div>
        </div>
        <!--<div class="book-item-line">-->
            <!--<div class="fl" style="line-height:20px;"> <strong>简介：</strong>{{ li['description'] }}</div>-->
        <!--</div>-->
        <div class="book-item-line">
            <div class="fl" style="line-height:20px;"> <strong>链接地址：</strong><a href="{{ li['link'] }}">{{ li['link'] }}</a> </div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>日期：</strong>{{li['date']}}</div>
            <div class="fr"> <strong>类型：</strong>{{li['type']}}</div>
        </div>
        <div class="book-item-line">
            <div class="fr">
                <strong>操作：</strong>
                <button value="{{li['id']}}" onClick="delete_article(this.value)" class="del_stu am-btn-danger">删除</button>
                <button value="{{li['id']}}" onClick="edit_article(this.value)" class="del_stu am-btn-primary">编辑</button>
            </div>
        </div>
     </div>
     {% endfor %}

    <div class="am-cf">
        <button type="text" id="back_" value="返回" onclick="javascript:window.location.href='./admin_center';" class="am-btn am-btn-default">返&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回</button>
    </div>

    <form method="post" action="/">

    </form>
</div>

<script type="text/javascript">

    function edit_article(val){
        window.location.href = "./admin_edit_article?id="+val;
    }

    function delete_article(val)
    {
        conf = window.confirm("确定删除该该文章？");
        if (conf) {
            var csrftoken = $('meta[name=csrf-token]').attr('content');
            $.ajaxSetup({
                beforeSend: function(xhr, settings) {
                    if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken)
                    }
                }
            });
            $.ajax({
                // 请求发送方式
                type: 'post',
                // 验证文件
                url: '/delete_article',
                // 用户输入的帐号密码
                data: {
                    'id': val
                },
                // 异步，不写默认为True
                async: 0,
                //请求成功后的回调
                success: function(data) {
                    alert("成功删除！");
                    window.location.reload();
                },
                error: function() {
                    alert('服务端异常');
                }
            });
        };
    }
</script>
</body>

</html>
